home *** CD-ROM | disk | FTP | other *** search
- Creating Screen Savers
-
- Overview:
-
- Have you ever wanted to write your own screensaver, but was told, "You can't do that in Visual Basic!" In fact, one person I heard
- from told me that Microsoft said that screensavers were impossible in Visual Basic. I didn't believe hem, and this is the result.
-
-
- Windows screensavers are easy and fun to write in Visual Basic, but there are some very important things to know.
- Experts can go straight to the Code Section of this document.
-
-
- Description:
-
- Application Title:
-
- A Windows screensaver is nothing more that a regular Windows executable file that has been renamed with the .scr extension.
- In Visual Basic, when you are making the executable file, you will need to set the Application Title in the Make EXE dialog box.
- This Application Title MUST be set to "SCRNSAVE title", where title is the text you want displayed in the Control Panel
- screensaver dropdown box.
-
-
-
- Command Line Arguments:
-
- When Windows starts up a screensaver it calls it with the "/s" argument, and when it wants to Setup the screensaver it uses the
- "/c" argument. So, we use a code module called Banner.BAS. In Banner.BAS you will see that a Select Case statement
- is used to capture this argument. You will need to change the Startup Form in the options|Project Dialog Box to Sub Main.
-
-
-
- Telling Windows that the Saver is Running:
-
- How long Windows waits before loading the screensaver is specified in the Control Panel. But if your screensaver doesn't tell
- Windows that it is running, Windows will reload the screensaver after that time passes again, even though the screensaver is
- already running. At first I thought I could remedy this situation by using VB 3.0's App object. The App.PrevInstance property will
- tell you whether or not there is a previous instance loaded.
-
-
- This should've worked, and I got many comments saying that I must have messed something up, but it didn't. For some reason,
- with the screensaver this kills both instances, not just the second. But there is a way out. To fix this I found a Windows API call
- which tells Windows that the screensaver is inactive, so don't load one. To use this API you need to use the API call
- SystemParametersInfo. This function is used to change system wide parameters, such as whether or not the screensaver is
- active. Be careful when using this call, since changes are permanent. You will need to make sure that your screensaver turns
- the screensaver back off when it has ended.
-
-
- See Sub Main, and Sub ExitNice in the Code Section.
-
-
- Hiding The Cursor:
-
- When you write a screensaver, you'll want it to hide the mouse cursor as well as whatever else your saver does. To do this you
- need to use the API call - ShowCursor. When ShowCursor( False ) is called, the cursor is hidden; when ShowCursor( True ) is
- called, the cursor is re-displayed. The Windows cursor is a shared object, so if your process hides it your process needs to
- redisplay it as well. See Code section.
-
-
- Knowing when to end:
-
- When your screensaver ends is up to you, but generally you'll want it to end if any of the following occur: mouse moves, button
- pressed, key pressed. To do this you will need to call a routine (ExitNice) to exit properly from each of these
- events in your screensaver form. You need to call this routine because this is where the other half of the
- SystemParametersInfo call is made. If this is left out, the screensaver won't run again after it wakes up. Another problem is that
- the MouseMove message is sent if the cursor is over the form, REGARDLESS if it is moved or not. So, you need to check to
- see if it has moved somehow. See the Code Section for my solution. (Not necessarily the prettiest.
-
-
- Config.Frm
-
- Windows will pass the "/c" argument to Sub Main if the "Setup" option is chosen from control panel. Here you can setup specific
- options for your screensaver. You might want to save these options in a .ini file (See Windows\Banner.Ini). Its up to you! If your
- Config.Frm has a "Test" feature which starts the screensaver from the Config form, then you will need to be careful about
- remembering to turn on the cursor after the screensaver starts, and then turn it off before it ends.
-
-
- Biker/Banner ScrnSave Forms
-
- The programs are setup to test within VB. Follow the inline instructions to make the SCR files
-
-
- Disclaimer/Distribution:
-
- This information is provided free of charge, and may be freely distributed. If you use portions of this document elsewhere, please
- indicate where you got it. All of the information here has been used and tested by me in Visual Basic 3.0 Professional. Use at
- your own risk. Visual Basic and Microsoft Windows are registered trademarks of Microsoft Corp.
-
-
- Full Credit must go to Peter Provost (TT tips article) for his original idea, from which this description is taken.
-
- Additional screensaver action code By: Rick Hunt CS 100307,2062
-
-
-